package models;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TreeSet;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name="Question")
@XmlType(propOrder={"text", "showNextTime", "answerList", "history"})
public class Question {

	private List<Answer> answerList = new ArrayList<Answer>();
	private String text;
	GregorianCalendar showNextTime;
	
	private TreeSet<HistoryElement> history = new TreeSet<HistoryElement>();
	
	public Question(){
		
	}
	
	public Question(String text, ArrayList<Answer> answerList, 
			GregorianCalendar shownexttime, TreeSet<HistoryElement> history){
		this();
		this.text = text;
		this.answerList = answerList;
		this.showNextTime = shownexttime;
		this.history = history;
	}

	public boolean isMultipleChoice(){
		return (answerList.size() > 1) ? true : false;
	}
	
	public ArrayList<Answer> getCorrectAnswers(){
		ArrayList<Answer> result = new ArrayList<Answer>();
		for (Answer a : this.getAnswerList()){
			if (a.isCorrect()){
				result.add(a);
			}
		}
		return result;
	}
	
	public ArrayList<Answer> getIncorrectAnswers(){
		ArrayList<Answer> result = new ArrayList<Answer>();
		for (Answer a : this.getAnswerList()){
			if (!a.isCorrect()){
				result.add(a);
			}
		}
		return result;
	}

	

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public List<Answer> getAnswerList() {
		return answerList;
	}

	public void setAnswerList(List<Answer> answerList) {
		this.answerList = answerList;
	}

	public TreeSet<HistoryElement> getHistory() {
		return history;
	}

	public void setHistory(TreeSet<HistoryElement> history) {
		this.history = history;
	}
	
}
